import { notFound, forbidden } from 'next/navigation';
import { fetchFeedPost, fetchFeedReplies } from '@/lib/api/feed/post';
import FeedPostView from './_component/FeedPostView';

export default async function FeedPostPage({ params }: { params: Promise<{ postID: string }> }) {
	const { postID } = await params;

	if (!/^\d+$/.test(postID)) {
		return forbidden();
	}

	const id = Number(postID);
	const [postRes, repliesRes] = await Promise.all([
		fetchFeedPost(id),
		fetchFeedReplies(id, 1, 30)
	]);

	if (!postRes.success || !postRes.data) {
		return notFound();
	}

	return (
		<FeedPostView
			post={postRes.data}
			initialReplies={repliesRes.data?.list ?? []}
			initialRepliesTotal={repliesRes.data?.total ?? 0}
		/>
	);
}